package com.moyun.finance.controller;

import com.moyun.finance.entity.Customer;
import com.moyun.finance.entity.Projects;
import com.moyun.finance.entity.Response;
import com.moyun.finance.service.ProjectsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/projects")
public class ProjectsController {
    @Autowired
    ProjectsService ps;

    //项目新增
    @RequestMapping("/save")
    public @ResponseBody Response save(@RequestBody Projects projects){
        Response res = ps.save(projects);
        return res;
    }

    //项目修改
    @RequestMapping("/update")
    public @ResponseBody Response update(@RequestBody Projects projects){
        Response res = ps.update(projects);
        return res;
    }

    //项目删除
    @RequestMapping("/delete")
    public @ResponseBody Response delete(@RequestBody Projects projects){
        Response res = ps.delete(projects);
        return res;
    }

    //查询指定公司所有项目信息
    @RequestMapping("/findAllByCompanyId")
    public @ResponseBody Response findAllByCompanyId(String companyId){
        List<Projects> projectses = ps.findAll(companyId);
        return new Response("",projectses,true);
    }

    //根据id查项目
    @RequestMapping("/findById")
    public @ResponseBody Response findOneById(String projectsId){
        Projects pro = ps.findOneById(projectsId);
        return new Response("",pro,true);
    }

    //根据公司和客户名字模糊查询
    @RequestMapping("/findByNameLike")
    public @ResponseBody Response findByNameLike(String companyId, String projectsName){
        List<Projects> cus = ps.findByNameLike(companyId, projectsName);
        return new Response("",cus,true);
    }

    //根据子菜单查本公司下所有
    @RequestMapping("/findByAllType")
    public @ResponseBody Response findByAllType(String companyId, String allTypeId){
        List<Projects> projectses = ps.findByAllType(companyId, allTypeId);
        return new Response("",projectses,true);
    }
}
